// 前端应用入口文件
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import App from './App.vue'
import { loadIconfont } from './plugins/iconfontLoader'

// 创建Vue应用实例
// 先加载 iconfont，降低首屏切换延迟
const envUrls = import.meta.env.VITE_ICONFONT_URLS || ''
const localIconfontUrl = new URL('../icon/font_3616790_037arq23xp86 2/iconfont.js', import.meta.url).href
const urlsToLoad = []
if (envUrls) urlsToLoad.push(...envUrls.split(',').map(s => s.trim()).filter(Boolean))
urlsToLoad.push(localIconfontUrl)
loadIconfont(urlsToLoad)

const app = createApp(App)

// 使用Element Plus组件库
app.use(ElementPlus, {
  locale: zhCn
})

// 注册所有Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 挂载应用
app.mount('#app')